import request from "@/utils/request.js";

export const listMerchant = async () => {
    const res = await request.get('/merchant/list');
    return res.map(e => ({...e, value: e.id, label: e.name}))
}
export const listUser = async () => {
    const res = await request.get('/user/list');
    return res.map(e => ({...e, value: e.id, label: e.nickname}))
}
export const listUserAddress = async () => {
    const res = await request.get('/userAddress/list');
    return res.map(e => ({...e, value: e.id, label: e.name}))
}

export const statusOptions = [
    {value: 1, label: '待付款', type: 'primary'},
    {value: 2, label: '待发货', type: 'info'},
    {value: 3, label: '待收货', type: 'warning'},
    {value: 4, label: '已完成', type: 'success'},
    {value: 5, label: '已取消', type: 'primary'},
]

export const fields = [
    {
        prop: 'orderNo',
        label: '订单号',
        type: 'text',
        width: '180',
        search: true,
    },
    {
        prop: 'userId',
        label: '购买用户',
        type: 'remote-select',
        api: listUser,
        width: '120',
    },
    {
        prop: 'addressId',
        label: '配送地址',
        type: 'remote-select',
        api: listUserAddress,
        width: '200',
    },
    {
        prop: 'merchantId',
        label: '所属商家',
        type: 'remote-select',
        api: listMerchant,
        width: '120',
    },
    {
        prop: 'totalPrice',
        label: '总金额',
        type: 'number',
        width: '120',
    },
    {
        prop: 'deliveryFee',
        label: '配送费',
        type: 'number',
        width: '120',
    },
    {
        prop: 'deliveryPerson',
        label: '配送员',
        type: 'text',
        width: '120',
        search: true,
    },
    {
        prop: 'deliveryPhone',
        label: '配送员电话',
        type: 'text',
        search: true,
        width: '120',
    },
    // {
    //     prop: 'estimatedArrivalTime',
    //     label: '预计到达时间',
    //     type: 'datetime',
    //     width: '190',
    // },
    {
        prop: 'status',
        label: '订单状态',
        type: 'tag',
        options: statusOptions,
        search: true,
        width: '120',
    },
    {
        prop: 'remark',
        label: '备注',
        type: 'longtext',
        width: '120',
    },
    {
        prop: 'createTime',
        label: '创建时间',
        type: 'datetime',
        formHidden: true,
        width: '190',
    },
    {
        prop: 'updateTime',
        label: '更新时间',
        type: 'datetime',
        formHidden: true,
        width: '190',
    }
]